{include file="public/head"}
<style type="text/css" media="screen">
    .x-body {
        min-width: 900px;
    }

    body {
        overflow-x: scroll;
    }
    .x-right button{
        display: initial;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav" style="height:30px">
        {if isession('user_id') == 1}
        <button class="layui-btn layui-btn-sm"
                onclick="x_admin_show('新建','add.html',500)">
            <i class="layui-icon layui-icon-add-circle"></i>新建
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
        </button>
        {else/}
        <button class="layui-btn layui-btn-sm layui-btn-normal"
                onclick="x_admin_show('发件人信息','shipper.html',500)">
            <i class="layui-icon layui-icon-form"></i>发件人信息
        </button>
        {/if}
        <span class="x-right">共有数据:<i class="i_count">{$list->total()}</i>条
            <button onclick="javascript:location.reload()" class="layui-btn-default ">
                <i class="layui-icon layui-icon-refresh"></i>
            </button>
        </span>
    </div>


    <table class="layui-table">
        <thead>
        <tr>
        {if isession('user_id') == 1}
            <th style="width: 75px;text-align:center">
                <div class="header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>物流名称</th>
            <th style="text-align:center">联系电话</th>
            <th style="width: 60px;text-align:center">状态</th>
            <th style="width: 120px;text-align:center">创建时间</th>
            <th style="width: 155px;text-align:center">操作</th>
        {else/}
            <th style="width: 45px;text-align:center"></th>
            <th>物流名称</th>
            <th style="text-align:center">联系电话</th>
            <th style="width: 120px;text-align:center">创建时间</th>
            {if checkHeadOfficeManage()}
            <th style="width: 130px;text-align:center">操作</th>
            {else/}
            <th style="width: 130px;text-align:center">操作</th>
            {/if}
        {/if}
        </tr>
        </thead>
        <tbody>
        {if isession('user_id') == 1}
        {volist name="list" id="vo"}
        <tr>
            <td style="text-align:center">
                <div class="layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'>
                    <i class="layui-icon">&#xe605;</i>
                </div>{$i}
            </td>
            <td>{$vo.name}</td>
            <td style="text-align:center">{$vo.phone}</td>
            <th style="text-align:center">
                {switch name="vo.status" }
                {case value="1"}<b style="color: green">启用</b>{/case}
                {case value="2"}<b style="color: red">禁用</b>{/case}
                {/switch}
            </th>
            <td style="text-align:center">{$vo['timestamp']|date="Y-m-d H:i",###}</td>
            <td>
                {if $vo.manual != 1}
                <button class="layui-btn layui-btn-xs" onclick="x_admin_show('{$vo.name}货运方式','listShip.html?id={$vo.id}')">
                    货运方式
                </button>
                {/if}
                <button class="layui-btn layui-btn-xs layui-btn-normal"
                        onclick="x_admin_show('编辑','edit.html?id={$vo.id}',500)">
                    编辑
                </button>
                <button onclick="del(this,'{$vo.id}')" class="layui-btn layui-btn-xs layui-btn-danger">
                    删除
                </button>
            </td>
        </tr>
        {/volist}
        {else/}
        {volist name="list" id="vo"}
        <tr>
            <td style="text-align:center">{$i}</td>
            <td>{$vo.name}</td>
            <td style="text-align:center">{$vo.phone}</td>
            <td style="text-align:center">{$vo['timestamp']|date="Y-m-d H:i",###}</td>
            <td style="text-align:center">
                <button class="layui-btn layui-btn-xs" onclick="x_admin_show('{$vo.name}货运方式','listShip.html?id={$vo.id}')">
                    货运方式
                </button>
                <button class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('参数设置','params.html?id={$vo.id}')">
                    参数设置
                </button>
            </td>
        </tr>
        {/volist}
        {/if}
        </tbody>
    </table>
    <div class="page">
        <div>
            {$list->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    //删除所有
    function delAll() {
        var count = $(".i_count")[0].innerText;
        var data = tableCheck.getData();
        var num = data.length;
        if (num == 0) {
            layer.msg("请选择需要删除的物流名称");
            return false;
        }
        layer.confirm('确认要全部删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/logistics/delect')}", {id: data}, function (data, textStatus, xhr) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                        $(".i_count").html(count - num);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    function del(obj, id) {
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/logistics/delect')}", {id: id}, function (data, textStatus, xhr) {
                console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
</script>
